package chapter11;

import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by VIC on 2017/1/25.
 */
public class Test15 {
    public static void main(String[] args) {
        Stack<String> stack = new Stack<String>();
        String expression = "+U+n+c---+e+r+t---+a-+i-+n+t+y---+-+r+u--+l+e+s--";
        List<String> arr = Arrays.asList(expression.split(""));
        ListIterator<String> ite = arr.listIterator();
        while(ite.hasNext()) {
            String currentStr = ite.next();
            if(("+").equals(currentStr)) {
                stack.push(ite.next());
            }else if(("-").equals(currentStr)) {
                System.out.print(stack.pop());
            }
        }
    }
}
